home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / bison / byacc.zoo / defs.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-01-23  |  6.2 KB  |  311 lines

  1. #include <assert.h>
  2. #include <ctype.h>
  3. #include <stdio.h>
  4.  
  5. #ifdef atarist    /* Gcc atari Tos */
  6. #include <stddef.h>
  7. #include <stdlib.h>
  8. #include <memory.h>
  9. #include <unixlib.h>
  10. #include <string.h>
  11. #endif
  12.  
  13. #ifdef minix    /* Gcc atari minix */
  14. #include <stddef.h>
  15. #include <stdlib.h>
  16. #include <memory.h>
  17. #include <unistd.h>
  18. #include <string.h>
  19. #endif
  20.  
  21. /*  machine-dependent definitions            */
  22. /*  the following definitions are for the Tahoe        */
  23. /*  they might have to be changed for other machines    */
  24.  
  25. /*  MAXCHAR is the largest unsigned character value    */
  26. /*  MAXSHORT is the largest value of a C short        */
  27. /*  MINSHORT is the most negative value of a C short    */
  28. /*  MAXTABLE is the maximum table size            */
  29. /*  BITS_PER_WORD is the number of bits in a C unsigned    */
  30. /*  WORDSIZE computes the number of words needed to    */
  31. /*    store n bits                    */
  32. /*  BIT returns the value of the n-th bit starting    */
  33. /*    from r (0-indexed)                */
  34. /*  SETBIT sets the n-th bit starting from r        */
  35.  
  36. #define    MAXCHAR        255
  37. #define    MAXSHORT    32767
  38. #define MINSHORT    -32768
  39. #define MAXTABLE    32500
  40. #define BITS_PER_WORD    32
  41. #define    WORDSIZE(n)    (((n)+(BITS_PER_WORD-1))/BITS_PER_WORD)
  42. #define    BIT(r, n)    ((((r)[(n)>>5])>>((n)&31))&1)
  43. #define    SETBIT(r, n)    ((r)[(n)>>5]|=((unsigned)1<<((n)&31)))
  44.  
  45.  
  46. /*  character names  */
  47.  
  48. #define    NUL        '\0'    /*  the null character  */
  49. #define    NEWLINE        '\n'    /*  line feed  */
  50. #define    SP        ' '     /*  space  */
  51. #define    BS        '\b'    /*  backspace  */
  52. #define    HT        '\t'    /*  horizontal tab  */
  53. #define    VT        '\013'  /*  vertical tab  */
  54. #define    CR        '\r'    /*  carriage return  */
  55. #define    FF        '\f'    /*  form feed  */
  56. #define    QUOTE        '\''    /*  single quote  */
  57. #define    DOUBLE_QUOTE    '\"'    /*  double quote  */
  58. #define    BACKSLASH    '\\'    /*  backslash  */
  59.  
  60.  
  61. /* defines for constructing filenames */
  62.  
  63. #ifndef atarist
  64. #define CODE_SUFFIX    ".code.c"
  65. #define    DEFINES_SUFFIX    ".tab.h"
  66. #define    OUTPUT_SUFFIX    ".tab.c"
  67. #define    VERBOSE_SUFFIX    ".output"
  68. #else
  69. #define CODE_SUFFIX    "cod.c"
  70. #define    DEFINES_SUFFIX    "tab.h"
  71. #define    OUTPUT_SUFFIX    "tab.c"
  72. #define    VERBOSE_SUFFIX    ".out"
  73. #endif
  74.  
  75. /* keyword codes */
  76.  
  77. #define TOKEN 0
  78. #define LEFT 1
  79. #define RIGHT 2
  80. #define NONASSOC 3
  81. #define MARK 4
  82. #define TEXT 5
  83. #define TYPE 6
  84. #define START 7
  85. #define UNION 8
  86. #define IDENT 9
  87.  
  88.  
  89. /*  symbol classes  */
  90.  
  91. #define UNKNOWN 0
  92. #define TERM 1
  93. #define NONTERM 2
  94.  
  95.  
  96. /*  the undefined value  */
  97.  
  98. #define UNDEFINED (-1)
  99.  
  100.  
  101. /*  action codes  */
  102.  
  103. #define SHIFT 1
  104. #define REDUCE 2
  105.  
  106.  
  107. /*  character macros  */
  108.  
  109. #define IS_IDENT(c)    (isalnum(c) || (c) == '_' || (c) == '.' || (c) == '$')
  110. #define    IS_OCTAL(c)    ((c) >= '0' && (c) <= '7')
  111. #define    NUMERIC_VALUE(c)    ((c) - '0')
  112.  
  113.  
  114. /*  symbol macros  */
  115.  
  116. #define ISTOKEN(s)    ((s) < start_symbol)
  117. #define ISVAR(s)    ((s) >= start_symbol)
  118.  
  119.  
  120. /*  storage allocation macros  */
  121.  
  122. #define CALLOC(k,n)    (calloc((unsigned)(k),(unsigned)(n)))
  123. #define    FREE(x)        (free((char*)(x)))
  124. #define MALLOC(n)    (malloc((unsigned)(n)))
  125. #define    NEW(t)        ((t*)allocate(sizeof(t)))
  126. #define    NEW2(n,t)    ((t*)allocate((unsigned)((n)*sizeof(t))))
  127. #define REALLOC(p,n)    (realloc((char*)(p),(unsigned)(n)))
  128.  
  129.  
  130. /*  the structure of a symbol table entry  */
  131.  
  132. typedef struct bucket bucket;
  133. struct bucket
  134. {
  135.     struct bucket *link;
  136.     struct bucket *next;
  137.     char *name;
  138.     char *tag;
  139.     short value;
  140.     short index;
  141.     short prec;
  142.     char class;
  143.     char assoc;
  144. };
  145.  
  146.  
  147. /*  the structure of the LR(0) state machine  */
  148.  
  149. typedef struct core core;
  150. struct core
  151. {
  152.     struct core *next;
  153.     struct core *link;
  154.     short number;
  155.     short accessing_symbol;
  156.     short nitems;
  157.     short items[1];
  158. };
  159.  
  160.  
  161. /*  the structure used to record shifts  */
  162.  
  163. typedef struct shifts shifts;
  164. struct shifts
  165. {
  166.     struct shifts *next;
  167.     short number;
  168.     short nshifts;
  169.     short shift[1];
  170. };
  171.  
  172.  
  173. /*  the structure used to store reductions  */
  174.  
  175. typedef struct reductions reductions;
  176. struct reductions
  177. {
  178.     struct reductions *next;
  179.     short number;
  180.     short nreds;
  181.     short rules[1];
  182. };
  183.  
  184.  
  185. /*  the structure used to represent parser actions  */
  186.  
  187. typedef struct action action;
  188. struct action
  189. {
  190.     struct action *next;
  191.     short symbol;
  192.     short number;
  193.     short prec;
  194.     char action_code;
  195.     char assoc;
  196.     char suppressed;
  197. };
  198.  
  199.  
  200. /* global variables */
  201.  
  202. extern char dflag;
  203. extern char lflag;
  204. extern char rflag;
  205. extern char tflag;
  206. extern char vflag;
  207.  
  208. extern char *myname;
  209. extern char *cptr;
  210. extern char *line;
  211. extern int lineno;
  212. extern int outline;
  213.  
  214. extern char *banner[];
  215. extern char *tables[];
  216. extern char *header[];
  217. extern char *body[];
  218. extern char *trailer[];
  219.  
  220. extern char *action_file_name;
  221. extern char *code_file_name;
  222. extern char *defines_file_name;
  223. extern char *input_file_name;
  224. extern char *output_file_name;
  225. extern char *text_file_name;
  226. extern char *union_file_name;
  227. extern char *verbose_file_name;
  228.  
  229. extern FILE *action_file;
  230. extern FILE *code_file;
  231. extern FILE *defines_file;
  232. extern FILE *input_file;
  233. extern FILE *output_file;
  234. extern FILE *text_file;
  235. extern FILE *union_file;
  236. extern FILE *verbose_file;
  237.  
  238. extern int nitems;
  239. extern int nrules;
  240. extern int nsyms;
  241. extern int ntokens;
  242. extern int nvars;
  243. extern int ntags;
  244.  
  245. extern char unionized;
  246. extern char line_format[];
  247.  
  248. extern int   start_symbol;
  249. extern char  **symbol_name;
  250. extern short *symbol_value;
  251. extern short *symbol_prec;
  252. extern char  *symbol_assoc;
  253.  
  254. extern short *ritem;
  255. extern short *rlhs;
  256. extern short *rrhs;
  257. extern short *rprec;
  258. extern char  *rassoc;
  259.  
  260. extern short **derives;
  261. extern char *nullable;
  262.  
  263. extern bucket *first_symbol;
  264. extern bucket *last_symbol;
  265.  
  266. extern int nstates;
  267. extern core *first_state;
  268. extern shifts *first_shift;
  269. extern reductions *first_reduction;
  270. extern short *accessing_symbol;
  271. extern core **state_table;
  272. extern shifts **shift_table;
  273. extern reductions **reduction_table;
  274. extern unsigned *LA;
  275. extern short *LAruleno;
  276. extern short *lookaheads;
  277. extern short *goto_map;
  278. extern short *from_state;
  279. extern short *to_state;
  280.  
  281. extern action **parser;
  282. extern int SRtotal;
  283. extern int RRtotal;
  284. extern short *SRconflicts;
  285. extern short *RRconflicts;
  286. extern short *defred;
  287. extern short *rules_used;
  288. extern short nunused;
  289. extern short final_state;
  290.  
  291. /* global functions */
  292.  
  293. extern char *allocate();
  294. extern bucket *lookup();
  295. extern bucket *make_bucket();
  296.  
  297.  
  298. /* system variables */
  299.  
  300. extern int errno;
  301.  
  302.  
  303. /* system functions */
  304. #if !defined(atarist) && !defined(minix)
  305. extern void free();
  306. extern char *calloc();
  307. extern char *malloc();
  308. extern char *realloc();
  309. extern char *strcpy();
  310. #endif
  311.